<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    
        //构造函数 创建书对象，构造函数构造对象的过程称之为 实例化
        function Book (bookName,pricre,author) {
            this.bookName = bookName;
            this.pricre = pricre;
            this.author = author;
            this.read = function (){
                console.log('阅读了'+ this.bookName);
                
            }
        }
        
        //构造出来的书对象 称之为 book函数的实例
        var book1 = new Book('白夜行','42.00','东野圭吾');
        book1.read();

        var book = new Book ('谁的青春不迷茫','38.00','刘同');
        book.read()

        //人的构造函数
        function Person(myName,bk) {
            this.myName = myName;
            //book 对象是 人这个对象的属性
            this.bk = bk;
        }

        //p1 这个人
        var p1 = new Person('老周',book);//创建了一个人 叫老周 他有一本书 叫 《谁的青春不迷茫》、
        p1.bk.read();//读取书名

        var p2 = new Person('老王',book1);
        p2.bk.read();
    </script>
</body>
</html>